package com.rybbaby.tss.front.tssStatistics.controller;

import com.rybbaby.tss.core.annotation.RequestLog;
import com.rybbaby.tss.core.annotation.Token;
import com.rybbaby.tss.core.bean.PageBean;
import com.rybbaby.tss.core.consts.RoleConsts;
import com.rybbaby.tss.core.hqlsearch.HqlGenerateUtil;
import com.rybbaby.tss.core.utils.*;
import com.rybbaby.tss.core.web.controller.BaseController;
import com.rybbaby.tss.front.tssMemberPackage.service.ITssMemberPackageService;
import com.rybbaby.tss.front.tssMemberPackageHistory.entity.TssMemberPackageHistory;
import com.rybbaby.tss.front.tssStatistics.entity.*;
import com.rybbaby.tss.front.tssStatistics.service.*;
import com.rybbaby.tss.platform.sysAdminUser.entity.SysAdminUser;
import com.rybbaby.tss.platform.sysAdminUser.service.ISysAdminUserService;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @description 员工表管理
 *
 * @author 雷春琼
 *
 * @createDate 2017-08-10 上午12:25:24
 */
@Controller
@RequestMapping(value = "ViewConsultancyStatisticsController")
public class ViewConsultancyStatisticsController extends BaseController {

	@Autowired
	private IViewConsultancyStatisticsService viewConsultancyStatisticsService;
	@Autowired
	private IViewOtherStatisticsService viewOtherStatisticsService;
	@Autowired
	private IViewAddedMemberDayService viewAddedMemberDayService;
	@Autowired
	private IViewAddedMemberMonthService viewAddedMemberMonthService;
	@Autowired
	private IViewStaffStatisticssService viewStaffStatisticssService;
	@Autowired
	private IViewClassesAttendceService viewClassesAttendceService;
	@Autowired
	private IViewParentingSurplusClassHourService viewParentingSurplusClassHourService;
	@Autowired
	private IViewTransitionSurplusAttendanceDayService viewTransitionSurplusAttendanceDayService;
	@Autowired
	private IViewStudentAttendanceService viewStudentAttendanceService;
	@Autowired
	private ITssMemberPackageService tssMemberPackageService;
	@Autowired
	private ISysAdminUserService sysAdminUserService;

	/**
	 * 获顾问业绩列表
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "获顾问业绩列表" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "consultancyStatisticsList" , method = RequestMethod.POST)
	public ModelAndView consultancyStatisticsList(ViewConsultancyStatistics entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewConsultancyStatisticsListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewConsultancyStatistics.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);

			String id = getParameter("id");
			String packageCreateTime_begin = getParameter("packageCreateTime_begin");
			String packageCreateTime_end = getParameter("packageCreateTime_end");
			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("id",id);
			paramHashMap.put("packageCreateTime_begin",packageCreateTime_begin);
			paramHashMap.put("packageCreateTime_end",packageCreateTime_end);

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

            if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
                dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
            } else{
                List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
                ids = StringUtils.join(idsList, "','");
                dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
            }

			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());
			PageBean pageBean = viewConsultancyStatisticsService.pageList(paramHashMap,paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(pageBean.getList().size()>0){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewConsultancyStatistics ConsultancyStatistics = (ViewConsultancyStatistics)pageBean.getList().get(i);
					Double sumAdded = ConsultancyStatistics.getSumAdded();
					Double sumRenewal = ConsultancyStatistics.getSumRenewal();
					Double sumRefund = ConsultancyStatistics.getSumRefund();

					BigDecimal bgSumAdded = new BigDecimal(0);
					BigDecimal bgSumRenewal = new BigDecimal(0);
					BigDecimal bgSumRefund = new BigDecimal(0);
					if(sumAdded!=null){
						bgSumAdded = new BigDecimal(sumAdded);
					}
					if(sumRenewal!=null){
						bgSumRenewal = new BigDecimal(sumRenewal);
					}
					if(sumRefund!=null){
						bgSumRefund = new BigDecimal(sumRefund);
					}

					Double sumPerformance = bgSumAdded.add(bgSumRenewal).subtract(bgSumRefund).doubleValue();

					Long addedNumber = ConsultancyStatistics.getAddedNumber();
					Long distributionNum = ConsultancyStatistics.getDistributionNum();

					BigDecimal bgAddedNumber = new BigDecimal(0);
					BigDecimal bgDistributionNum = new BigDecimal(0);
					BigDecimal hundred = new BigDecimal(100);
					if(addedNumber!=null){
						bgAddedNumber = new BigDecimal(addedNumber);
					}
					if(distributionNum!=null){
						bgDistributionNum = new BigDecimal(distributionNum);
					}

					Double attendanceRate = new Double(0);
					if(distributionNum != 0){
						attendanceRate = bgAddedNumber.multiply(hundred).divide(bgDistributionNum, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewConsultancyStatistics) pageBean.getList().get(i)).setAttendanceRate(attendanceRate.toString()+"%");
					}

					((ViewConsultancyStatistics) pageBean.getList().get(i)).setSumPerformance(sumPerformance);

				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 获得其它业绩列表
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "获得其它业绩列表" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "otherStatistics" , method = RequestMethod.POST)
	public ModelAndView otherStatistics(ViewOtherStatistics entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewOtherStatisticsListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewOtherStatistics.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			String id = getParameter("id");
			String paymentCreateTime_begin = getParameter("paymentCreateTime_begin");
			String paymentCreateTime_end = getParameter("paymentCreateTime_end");

			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("id",id);
			paramHashMap.put("paymentCreateTime_begin",paymentCreateTime_begin);
			paramHashMap.put("paymentCreateTime_end",paymentCreateTime_end);

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewOtherStatisticsService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(pageBean.getList().size()>0){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewOtherStatistics OtherStatistics = (ViewOtherStatistics)pageBean.getList().get(i);
					Double sumAmount = OtherStatistics.getSumAmount();
					Double sumAmout = OtherStatistics.getSumAmout();

					BigDecimal bgsumAmount = new BigDecimal(0);
					BigDecimal bgsumAmout = new BigDecimal(0);
					if(sumAmount!=null){
						bgsumAmount = new BigDecimal(sumAmount);
					}
					if(sumAmout!=null){
						bgsumAmout = new BigDecimal(sumAmout);
					}

					Double sumPerformance = bgsumAmount.subtract(bgsumAmout).doubleValue();

					((ViewOtherStatistics) pageBean.getList().get(i)).setSumPerformance(sumPerformance);

				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}

		/*public static void main(String[] args) throws Exception {
			String beginDate = "2016-12-30";//开始时间
			String endDate = "2017-01-07";//结束时间


			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Calendar cal = Calendar.getInstance();
			cal.setTime(sdf.parse(beginDate));

			cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + 1);
			cal.getTimeInMillis();

			ArrayList<ViewAddedMemberDay> addedMembers = new ArrayList<ViewAddedMemberDay>();
			ViewAddedMemberDay viewAddedMember1 = new ViewAddedMemberDay();
			viewAddedMember1.setAdded(2);
			viewAddedMember1.setRenewal(3);
			viewAddedMember1.setType(1);
			viewAddedMember1.setCreateDate(sdf.parse("2017-01-06"));
			addedMembers.add(viewAddedMember1);
			ViewAddedMemberDay viewAddedMember2= new ViewAddedMemberDay();
			viewAddedMember2.setAdded(3);
			viewAddedMember2.setRenewal(2);
			viewAddedMember2.setType(1);
			viewAddedMember2.setCreateDate(sdf.parse("2017-01-03"));
			addedMembers.add(viewAddedMember2);

			ArrayList<ViewAddedMemberDay> viewAddedMembers = new ArrayList<ViewAddedMemberDay>();
			int j = 0;

			for (long d = cal.getTimeInMillis(); d <= sdf.parse(endDate).getTime(); d = cal.getTimeInMillis()) {
				System.out.println(sdf.format(d));
				ViewAddedMemberDay viewAddedMember = new ViewAddedMemberDay();
				viewAddedMember.setAdded(0);
				viewAddedMember.setRenewal(0);
				viewAddedMember.setType(1);
				viewAddedMember.setCreateDate(sdf.parse(sdf.format(d)));
				viewAddedMembers.add(j,viewAddedMember);
				for (int i = 0; i < addedMembers.size(); i++) {
					if (sdf.format(addedMembers.get(i).getCreateDate()).equals(sdf.format(d))) {
						viewAddedMembers.add(j,addedMembers.get(i));
					}
				}
				j = j+1;
			}
		}*/
		/*public static void main(String[] args) throws Exception {
			String beginDate = "2015-12-30";//开始时间
			String endDate = "2017-01-07";//结束时间

			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			Calendar cal = Calendar.getInstance();
			cal.setTime(sdf.parse(beginDate));
			ArrayList<String> strings = new ArrayList<>();
			int i = 1;
			for (long d = cal.getTimeInMillis(); d <= sdf.parse(endDate).getTime(); d = get_D_Plaus_1(cal)) {
				System.out.println(i);
				System.out.println(sdf.format(d));
				i = i+1;
				strings.add(sdf.format(d));
			}
		}

		public static long get_D_Plaus_1(Calendar c) {
			c.set(Calendar.MONTH, c.get(Calendar.MONTH) + 1);
			return c.getTimeInMillis();
		}*/

	/**
	 * 新增会员统计（日）
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "新增会员统计（日）" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "dayAddedMember" , method = RequestMethod.GET)
	public ModelAndView dayAddedMember(ViewAddedMemberDay entity , PageBean paramPageBean) throws ParseException {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("dayAddedMemberView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewAddedMemberDay.class);
			String createData_begain = getParameter("createDate_begin");
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			if (StringUtils.isBlank(createData_begain)) {
				Calendar lastDate = Calendar.getInstance();
				lastDate.add(Calendar.DAY_OF_YEAR, -6);

				String defaultCreateBefore7Day = sdf.format(lastDate.getTime());
				unLockMap.put("createDate_begin",new String[]{defaultCreateBefore7Day});
			}
			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
			}
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			/*dc.add(Restrictions.eq("type",1));*/

			List<ViewAddedMemberDay> addedMembers = viewAddedMemberDayService.findByDetached(dc);

			String[] createDate_begins = unLockMap.get("createDate_begin");
			String createDate_begin = createDate_begins[0];
			String[] createDate_ends = unLockMap.get("createDate_end");
			String createDate_end = "";
			if(createDate_ends!=null){
				createDate_end = createDate_ends[0];
			}else {
				createDate_end = sdf.format(new Date());
			}

			String beginDate = createDate_begin;//开始时间
			String endDate = createDate_end;//结束时间


			ArrayList<ViewAddedMemberDay> viewAddedMemberDays = new ArrayList<ViewAddedMemberDay>();
			int j = 0;
			ArrayList<String> allDay = DateUtil.getAllDay(beginDate, endDate,"yyyy-MM-dd");

			for (int i = 0; i < allDay.size(); i++) {

				System.out.println(allDay.get(i));
				ViewAddedMemberDay viewAddedMemberDay = new ViewAddedMemberDay();
				viewAddedMemberDay.setAdded(0);
				viewAddedMemberDay.setRenewal(0);
				viewAddedMemberDay.setType(1);
				viewAddedMemberDay.setCreateDate(sdf.parse(allDay.get(i)));
				viewAddedMemberDays.add(j, viewAddedMemberDay);
				for (int h = 0; h < addedMembers.size(); h++) {
					if (sdf.format(addedMembers.get(h).getCreateDate()).equals(allDay.get(i))) {
						viewAddedMemberDays.add(j,addedMembers.get(h));
					}
				}
				j = j+1;
			}


			/*String s = JSONUtil.toJsonStr(pageBean.getList());
			AjaxJsonResponse ajr = new AjaxJsonResponse();
			ajr.setData(pageBean.getList().toArray());*/

			mav.addObject("type" , entity.getType());
			mav.addObject("date" , "1");
			mav.addObject("viewAddedMembers" , viewAddedMemberDays);
			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 新增会员统计（月）
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "新增会员统计（月）" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "monthAddedMember" , method = RequestMethod.GET)
	public ModelAndView monthAddedMember(ViewAddedMemberMonth entity , PageBean paramPageBean) throws ParseException {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("monthAddedMemberView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewAddedMemberMonth.class);
			String createData_begain = getParameter("createDate_begin");
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			if (StringUtils.isBlank(createData_begain)) {
				Calendar lastDate = Calendar.getInstance();
				lastDate.add(Calendar.MONTH, -5);

				String defaultCreateBefore7Day = sdf.format(lastDate.getTime());
				unLockMap.put("createDate_begin",new String[]{defaultCreateBefore7Day});
			}
			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
			}
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			/*dc.add(Restrictions.eq("type",1));*/

			List<ViewAddedMemberMonth> addedMembers = viewAddedMemberMonthService.findByDetached(dc);

			String[] createDate_begins = unLockMap.get("createDate_begin");
			String createDate_begin = createDate_begins[0];
			String[] createDate_ends = unLockMap.get("createDate_end");
			String createDate_end = "";
			if(createDate_ends!=null){
				createDate_end = createDate_ends[0];
			}else {
				createDate_end = sdf.format(new Date());
			}

			String beginDate = createDate_begin;//开始时间
			String endDate = createDate_end;//结束时间


			ArrayList<ViewAddedMemberMonth> viewAddedMemberMonths = new ArrayList<ViewAddedMemberMonth>();
			int j = 0;
			ArrayList<String> allDay = DateUtil.getAllMonth(beginDate, endDate,"yyyy-MM");

			for (int i = 0; i < allDay.size(); i++) {

				System.out.println(allDay.get(i));
				ViewAddedMemberMonth viewAddedMemberMonth = new ViewAddedMemberMonth();
				viewAddedMemberMonth.setAdded(0);
				viewAddedMemberMonth.setRenewal(0);
				viewAddedMemberMonth.setType(1);
				viewAddedMemberMonth.setCreateDate(allDay.get(i));
				viewAddedMemberMonths.add(j, viewAddedMemberMonth);
				for (int h = 0; h < addedMembers.size(); h++) {
					if (addedMembers.get(h).getCreateDate().equals(allDay.get(i))) {
						viewAddedMemberMonths.add(j,addedMembers.get(h));
					}
				}
				j = j+1;
			}


			/*String s = JSONUtil.toJsonStr(pageBean.getList());
			AjaxJsonResponse ajr = new AjaxJsonResponse();
			ajr.setData(pageBean.getList().toArray());*/

			mav.addObject("type" , entity.getType());
			mav.addObject("date" , "2");
			mav.addObject("viewAddedMembers" , viewAddedMemberMonths);
			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}

	/**
	 * 亲子会员剩余课时
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "亲子会员剩余课时" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "parentingSurplusClassHourList" , method = RequestMethod.POST)
	public ModelAndView parentingSurplusClassHourList(ViewParentingSurplusClassHour entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewParentingSurplusClassHourListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewParentingSurplusClassHour.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			String id = getParameter("id");
			String nickName = getParameter("nickName");
			String contactPhone = getParameter("contactPhone");
			String birthdayDate_begin = getParameter("birthdayDate_begin");
			String birthdayDate_end = getParameter("birthdayDate_end");
			String surplusClassHours_begin = getParameter("surplusClassHours_begin");
			String surplusClassHours_end = getParameter("surplusClassHours_end");
			String surplusPresentClassHours_begin = getParameter("surplusPresentClassHours_begin");
			String surplusPresentClassHours_end = getParameter("surplusPresentClassHours_end");
			String balances_begin = getParameter("balances_begin");
			String balances_end = getParameter("balances_end");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");

			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("type","1");
			paramHashMap.put("nickName",nickName);
			paramHashMap.put("contactPhone",contactPhone);
			paramHashMap.put("birthdayDate_begin",birthdayDate_begin);
			paramHashMap.put("birthdayDate_end",birthdayDate_end);
			paramHashMap.put("surplusClassHours_begin",surplusClassHours_begin);
			paramHashMap.put("surplusClassHours_end",surplusClassHours_end);
			paramHashMap.put("surplusPresentClassHours_begin",surplusPresentClassHours_begin);
			paramHashMap.put("surplusPresentClassHours_end",surplusPresentClassHours_end);
			paramHashMap.put("balances_begin",balances_begin);
			paramHashMap.put("balances_end",balances_end);
			paramHashMap.put("startTime_begin",startTime_begin);

			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			Date parse = formatter.parse(formatter.format(new Date()));
			if(endTime_end != null && !"".equals(endTime_end)){
				Date date = formatter.parse(endTime_end);
				if (parse.getTime() > date.getTime()) {
					paramHashMap.put("endTime_end",endTime_end);
				}
			}

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}


			PageBean pageBean = viewParentingSurplusClassHourService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(startTime_begin != null && !startTime_begin.equals("")){
				List<Map<String,Object>> mapList = tssMemberPackageService.finByHistory(startTime_begin,"2");
				for (int i = 0; i < mapList.size(); i++) {
					for (int j = 0; j < pageBean.getList().size(); j++) {
						ViewParentingSurplusClassHour parentingSurplusClassHour = (ViewParentingSurplusClassHour) pageBean.getList().get(j);
						Map<String, Object> map = mapList.get(i);
						if(parentingSurplusClassHour.getId().equals(map.get("id"))){
							BigDecimal consumptionAttendanceDaysMap = (BigDecimal) map.get("consumptionAttendanceDays");
							if(consumptionAttendanceDaysMap!=null){
								BigDecimal consumptionClassHoursEntity = parentingSurplusClassHour.getConsumptionClassHours();
								BigDecimal consumptionClassHours = consumptionClassHoursEntity.subtract(consumptionAttendanceDaysMap);
								parentingSurplusClassHour.setConsumptionClassHours(consumptionClassHours);
							}
						}
					}
				}
			}


			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}catch (java.lang.Exception e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 过度会员剩余课时
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "过度会员剩余课时" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "transitionSurplusAttendanceDayList" , method = RequestMethod.POST)
	public ModelAndView transitionSurplusAttendanceDayList(ViewTransitionSurplusAttendanceDay entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewTransitionSurplusAttendanceDayListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewTransitionSurplusAttendanceDay.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			String id = getParameter("id");
			String nickName = getParameter("nickName");
			String contactPhone = getParameter("contactPhone");
			String birthdayDate_begin = getParameter("birthdayDate_begin");
			String birthdayDate_end = getParameter("birthdayDate_end");
			String surplusClassHours_begin = getParameter("surplusClassHours_begin");
			String surplusClassHours_end = getParameter("surplusClassHours_end");
			String remediationClassHours_begin = getParameter("remediationClassHours_begin");
			String remediationClassHours_end = getParameter("remediationClassHours_end");
			String surplusPresentClassHours_begin = getParameter("surplusPresentClassHours_begin");
			String surplusPresentClassHours_end = getParameter("surplusPresentClassHours_end");
			String balances_begin = getParameter("balances_begin");
			String balances_end = getParameter("balances_end");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");

			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("type","2");
			paramHashMap.put("nickName",nickName);
			paramHashMap.put("contactPhone",contactPhone);
			paramHashMap.put("birthdayDate_begin",birthdayDate_begin);
			paramHashMap.put("birthdayDate_end",birthdayDate_end);
			paramHashMap.put("surplusClassHours_begin",surplusClassHours_begin);
			paramHashMap.put("surplusClassHours_end",surplusClassHours_end);
			paramHashMap.put("remediationClassHours_begin",remediationClassHours_begin);
			paramHashMap.put("remediationClassHours_end",remediationClassHours_end);
			paramHashMap.put("surplusPresentClassHours_begin",surplusPresentClassHours_begin);
			paramHashMap.put("surplusPresentClassHours_end",surplusPresentClassHours_end);
			paramHashMap.put("balances_begin",balances_begin);
			paramHashMap.put("balances_end",balances_end);
			paramHashMap.put("startTime_begin",startTime_begin);

			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
			Date parse = formatter.parse(formatter.format(new Date()));
			if(endTime_end != null && !"".equals(endTime_end)){
				Date date = formatter.parse(endTime_end);
				if (parse.getTime() > date.getTime()) {
					paramHashMap.put("endTime_end",endTime_end);
				}
			}

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewTransitionSurplusAttendanceDayService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(startTime_begin != null && !startTime_begin.equals("")){
				List<Map<String,Object>> mapList = tssMemberPackageService.finByHistory(startTime_begin,"2");
				for (int i = 0; i < mapList.size(); i++) {
					for (int j = 0; j < pageBean.getList().size(); j++) {
						ViewTransitionSurplusAttendanceDay transitionSurplusAttendanceDay = (ViewTransitionSurplusAttendanceDay) pageBean.getList().get(j);
						Map<String, Object> map = mapList.get(i);
						if(transitionSurplusAttendanceDay.getId().equals(map.get("id"))){
							BigDecimal consumptionClassHoursMap = (BigDecimal) map.get("consumptionClassHours");
							if(consumptionClassHoursMap!=null){
								BigDecimal consumptionClassHoursEntity = transitionSurplusAttendanceDay.getConsumptionAttendanceDays();
								BigDecimal consumptionClassHours = consumptionClassHoursEntity.subtract(consumptionClassHoursMap);
								transitionSurplusAttendanceDay.setConsumptionAttendanceDays(consumptionClassHours);
							}
						}
					}
				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (ParseException e1) {
				e1.printStackTrace();
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 亲子会员出勤统计
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "亲子会员出勤统计" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "parentingStudentAttendanceList" , method = RequestMethod.POST)
	public ModelAndView parentingStudentAttendanceList(ViewStudentAttendance entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewParentsStudentAttendanceListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewStudentAttendance.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//dc.add(Restrictions.eq("type",1));
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			String id = getParameter("id");
			String nickName = getParameter("nickName");
			String contactPhone = getParameter("contactPhone");
			String attendanceRate_begin = getParameter("attendanceRate_begin");
			String attendanceRate_end = getParameter("attendanceRate_end");
			String maxUpdateTime_begin = getParameter("maxUpdateTime_begin");
			String maxUpdateTime_end = getParameter("maxUpdateTime_end");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");

			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("id",id);
			paramHashMap.put("type","1");
			paramHashMap.put("nickName",nickName);
			paramHashMap.put("contactPhone",contactPhone);
			paramHashMap.put("maxUpdateTime_begin",maxUpdateTime_begin);
			paramHashMap.put("maxUpdateTime_end",maxUpdateTime_end);
			paramHashMap.put("startTime_begin",startTime_begin);
			paramHashMap.put("endTime_end",endTime_end);

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewStudentAttendanceService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			List<ViewStudentAttendance> viewStudentAttendances = new ArrayList<ViewStudentAttendance>();

			if(pageBean.getList()!=null){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewStudentAttendance StudentAttendance = (ViewStudentAttendance)pageBean.getList().get(i);
					Long sumAttendance = StudentAttendance.getSumAttendance();
					Long sumReported = StudentAttendance.getSumReported();

					BigDecimal bgSumAttendance = new BigDecimal(0);
					BigDecimal bgSumReported = new BigDecimal(0);
					if(sumAttendance!=null){
						bgSumAttendance = new BigDecimal(sumAttendance);
					}
					if(bgSumReported!=null){
						bgSumReported = new BigDecimal(sumReported);
					}
					BigDecimal hundred = new BigDecimal(100);
					Double attendanceRate = new Double(0);
					if(sumReported != 0){
						attendanceRate = bgSumAttendance.multiply(hundred).divide(bgSumReported, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewStudentAttendance) pageBean.getList().get(i)).setAttendanceRate(attendanceRate+"%");

						if((attendanceRate_begin != null && !attendanceRate_begin.equals("") )&& (attendanceRate_end == null || attendanceRate_end.equals(""))){
							if(attendanceRate > Double.valueOf(attendanceRate_begin.toString())){
								viewStudentAttendances.add(((ViewStudentAttendance) pageBean.getList().get(i)));
							}
						}
						if((attendanceRate_end != null && !attendanceRate_end.equals("") )&& (attendanceRate_begin == null || attendanceRate_begin.equals(""))){
							if(attendanceRate < Double.valueOf(attendanceRate_end.toString())){
								viewStudentAttendances.add(((ViewStudentAttendance) pageBean.getList().get(i)));
							}
						}
						if(attendanceRate_end != null && !attendanceRate_end.equals("") && attendanceRate_begin != null && !attendanceRate_begin.equals("")){
							if(attendanceRate > Double.valueOf(attendanceRate_begin.toString())){
								if(attendanceRate < Double.valueOf(attendanceRate_end.toString())) {
									viewStudentAttendances.add(((ViewStudentAttendance) pageBean.getList().get(i)));
								}
							}
						}
					}else {
						((ViewStudentAttendance) pageBean.getList().get(i)).setAttendanceRate("0%");
					}



				}
				if((attendanceRate_begin != null && !attendanceRate_begin.equals("") )&& (attendanceRate_end == null || attendanceRate_end.equals(""))){
					pageBean.setList(viewStudentAttendances);
				}
				if((attendanceRate_end != null && !attendanceRate_end.equals("") )&& (attendanceRate_begin == null || attendanceRate_begin.equals(""))){
					pageBean.setList(viewStudentAttendances);
				}
				if(attendanceRate_end != null && !attendanceRate_end.equals("") && attendanceRate_begin != null && !attendanceRate_begin.equals("")){
					pageBean.setList(viewStudentAttendances);
				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 过渡会员出勤统计
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "过渡会员出勤统计" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "transitionStudentAttendanceList" , method = RequestMethod.POST)
	public ModelAndView transitionStudentAttendanceList(ViewStudentAttendance entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewTransitionStudentAttendanceListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewStudentAttendance.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//dc.add(Restrictions.eq("type",2));
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			String id = getParameter("id");
			String nickName = getParameter("nickName");
			String contactPhone = getParameter("contactPhone");
			String attendanceRate_begin = getParameter("attendanceRate_begin");
			String attendanceRate_end = getParameter("attendanceRate_end");
			String maxUpdateTime_begin = getParameter("maxUpdateTime_begin");
			String maxUpdateTime_end = getParameter("maxUpdateTime_end");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");

			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("id",id);
			paramHashMap.put("type","2");
			paramHashMap.put("nickName",nickName);
			paramHashMap.put("contactPhone",contactPhone);
			paramHashMap.put("maxUpdateTime_begin",maxUpdateTime_begin);
			paramHashMap.put("maxUpdateTime_end",maxUpdateTime_end);
			paramHashMap.put("startTime_begin",startTime_begin);
			paramHashMap.put("endTime_end",endTime_end);

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewStudentAttendanceService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			List<ViewStudentAttendance> viewStudentAttendances = new ArrayList<ViewStudentAttendance>();

			if(pageBean.getList()!=null){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewStudentAttendance StudentAttendance = (ViewStudentAttendance)pageBean.getList().get(i);
					Long sumAttendance = StudentAttendance.getSumAttendance();
					Long sumReported = StudentAttendance.getSumReported();

					BigDecimal bgSumAttendance = new BigDecimal(0);
					BigDecimal bgSumReported = new BigDecimal(0);
					if(sumAttendance!=null){
						bgSumAttendance = new BigDecimal(sumAttendance);
					}
					if(bgSumReported!=null){
						bgSumReported = new BigDecimal(sumReported);
					}
					BigDecimal hundred = new BigDecimal(100);
					Double attendanceRate = new Double(0);
					if(sumReported != 0){
						attendanceRate = bgSumAttendance.multiply(hundred).divide(bgSumReported, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewStudentAttendance) pageBean.getList().get(i)).setAttendanceRate(attendanceRate+"%");

						if((attendanceRate_begin != null && !attendanceRate_begin.equals("") )&& (attendanceRate_end == null || attendanceRate_end.equals(""))){
							if(attendanceRate > Double.valueOf(attendanceRate_begin.toString())){
								viewStudentAttendances.add(((ViewStudentAttendance) pageBean.getList().get(i)));
							}
						}
						if((attendanceRate_end != null && !attendanceRate_end.equals("") )&& (attendanceRate_begin == null || attendanceRate_begin.equals(""))){
							if(attendanceRate < Double.valueOf(attendanceRate_end.toString())){
								viewStudentAttendances.add(((ViewStudentAttendance) pageBean.getList().get(i)));
							}
						}
						if(attendanceRate_end != null && !attendanceRate_end.equals("") && attendanceRate_begin != null && !attendanceRate_begin.equals("")){
							if(attendanceRate > Double.valueOf(attendanceRate_begin.toString())){
								if(attendanceRate < Double.valueOf(attendanceRate_end.toString())) {
									viewStudentAttendances.add(((ViewStudentAttendance) pageBean.getList().get(i)));
								}
							}
						}
					}else {
						((ViewStudentAttendance) pageBean.getList().get(i)).setAttendanceRate("0%");
					}



				}
				if((attendanceRate_begin != null && !attendanceRate_begin.equals("") )&& (attendanceRate_end == null || attendanceRate_end.equals(""))){
					pageBean.setList(viewStudentAttendances);
				}
				if((attendanceRate_end != null && !attendanceRate_end.equals("") )&& (attendanceRate_begin == null || attendanceRate_begin.equals(""))){
					pageBean.setList(viewStudentAttendances);
				}
				if(attendanceRate_end != null && !attendanceRate_end.equals("") && attendanceRate_begin != null && !attendanceRate_begin.equals("")){
					pageBean.setList(viewStudentAttendances);
				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}

	/**
	 * 亲子班级出勤统计
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "亲子班级出勤统计" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "parentingClassesAttendceList" , method = RequestMethod.POST)
	public ModelAndView parentingClassesAttendceList(ViewClassesAttendce entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewParentingClassesAttendceListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewClassesAttendce.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//dc.add(Restrictions.eq("type",1));
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());
			String roomId = getParameter("roomId");
			String systemId = getParameter("systemId");
			String classTime_begin = getParameter("classTime_begin");
			String classTime_end = getParameter("classTime_end");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");
			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("roomId",roomId);
			paramHashMap.put("systemId",systemId);
			paramHashMap.put("type","1");
			paramHashMap.put("classTime_begin",classTime_begin);
			paramHashMap.put("classTime_end",classTime_end);
			paramHashMap.put("startTime_begin",startTime_begin);
			paramHashMap.put("endTime_end",endTime_end);

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewClassesAttendceService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(pageBean.getList()!=null){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewClassesAttendce ClassesAttendce = (ViewClassesAttendce)pageBean.getList().get(i);
					Long sumAttendance = ClassesAttendce.getSumAttendance();
					Long sumShouldAttend = ClassesAttendce.getSumShouldAttend();

					BigDecimal bgsumAmount = new BigDecimal(0);
					BigDecimal bgsumAmout = new BigDecimal(0);
					if(sumAttendance!=null){
						bgsumAmount = new BigDecimal(sumAttendance);
					}
					if(sumShouldAttend!=null){
						bgsumAmout = new BigDecimal(sumShouldAttend);
					}
					BigDecimal hundred = new BigDecimal(100);
					Double attendanceRate = new Double(0);
					if(sumShouldAttend != 0){
						attendanceRate = bgsumAmount.multiply(hundred).divide(bgsumAmout, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewClassesAttendce) pageBean.getList().get(i)).setAttendanceRate(attendanceRate+"%");
					}else {
						((ViewClassesAttendce) pageBean.getList().get(i)).setAttendanceRate("0%");
					}


				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 过渡班级出勤统计
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "过渡班级出勤统计" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "transitionClassesAttendceList" , method = RequestMethod.POST)
	public ModelAndView transitionClassesAttendceList(ViewClassesAttendce entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewTransitionClassesAttendceListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewClassesAttendce.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//dc.add(Restrictions.eq("type",2));
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			String roomId = getParameter("roomId");
			String systemId = getParameter("systemId");
			String classTime_begin = getParameter("classTime_begin");
			String classTime_end = getParameter("classTime_end");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");
			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("roomId",roomId);
			paramHashMap.put("systemId",systemId);
			paramHashMap.put("type","2");
			paramHashMap.put("classTime_begin",classTime_begin);
			paramHashMap.put("classTime_end",classTime_end);
			paramHashMap.put("startTime_begin",startTime_begin);
			paramHashMap.put("endTime_end",endTime_end);

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewClassesAttendceService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(pageBean.getList()!=null){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewClassesAttendce ClassesAttendce = (ViewClassesAttendce)pageBean.getList().get(i);
					Long sumAttendance = ClassesAttendce.getSumAttendance();
					Long sumShouldAttend = ClassesAttendce.getSumShouldAttend();

					BigDecimal bgsumAmount = new BigDecimal(0);
					BigDecimal bgsumAmout = new BigDecimal(0);
					if(sumAttendance!=null){
						bgsumAmount = new BigDecimal(sumAttendance);
					}
					if(sumShouldAttend!=null){
						bgsumAmout = new BigDecimal(sumShouldAttend);
					}
					BigDecimal hundred = new BigDecimal(100);
					Double attendanceRate = new Double(0);
					if(sumShouldAttend != 0){
						attendanceRate = bgsumAmount.multiply(hundred).divide(bgsumAmout, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewClassesAttendce) pageBean.getList().get(i)).setAttendanceRate(attendanceRate+"%");
					}else {
						((ViewClassesAttendce) pageBean.getList().get(i)).setAttendanceRate("0%");
					}


				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}
		return mav;
	}

	/**
	 * 教师亲子业绩统计
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "教师亲子业绩统计" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "parentingStaffStatisticsList" , method = RequestMethod.POST)
	public ModelAndView parentingStaffStatisticsList(ViewStaffStatistics entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewParentingStaffStatisticsListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewStaffStatistics.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			String id = getParameter("id");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");
			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("id",id);
			paramHashMap.put("type","1");
			paramHashMap.put("startTime_begin",startTime_begin);
			paramHashMap.put("endTime_end",endTime_end);
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewStaffStatisticssService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(pageBean.getList()!=null){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewStaffStatistics StaffStatistics = (ViewStaffStatistics)pageBean.getList().get(i);
					Long sumAttendance = StaffStatistics.getSumAttendance();
					Long shouldAttend = StaffStatistics.getShouldAttend();

					BigDecimal bgSumAttendance = new BigDecimal(0);
					BigDecimal bgShouldAttend = new BigDecimal(0);
					if(sumAttendance!=null){
						bgSumAttendance = new BigDecimal(sumAttendance);
					}
					if(bgShouldAttend!=null){
						bgShouldAttend = new BigDecimal(shouldAttend);
					}
					BigDecimal hundred = new BigDecimal(100);
					Double attendanceRate = new Double(0);
					if(shouldAttend != 0){
						attendanceRate = bgSumAttendance.multiply(hundred).divide(bgShouldAttend, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewStaffStatistics) pageBean.getList().get(i)).setAttendanceRate(attendanceRate+"%");
					}else {
						((ViewStaffStatistics) pageBean.getList().get(i)).setAttendanceRate("0%");
					}


				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}
	/**
	 * 教师过渡业绩统计
	 *
	 * @return
	 * @throws IOException
	 */
	@RequestLog(content = "教师过渡业绩统计" , save = true)
	@Token(validateToken = false)
	@RequestMapping(value = "transitionStaffStatisticsList" , method = RequestMethod.POST)
	public ModelAndView transitionStaffStatisticsList(ViewStaffStatistics entity , PageBean paramPageBean) {
		ModelAndView mav = new ModelAndView(PropertiesReadUtil.getStringProperty("ViewTransitionStaffStatisticsListView"));
		try {
			Map<String , String []> unLockMap = getParameterMap(request);
			DetachedCriteria dc = DetachedCriteria.forClass(ViewStaffStatistics.class);
			HqlGenerateUtil.fillDetachedCriteria(dc , entity , unLockMap);
			//dc.add(Restrictions.eq("type",2));
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			String id = getParameter("id");
			String startTime_begin = getParameter("startTime_begin");
			String endTime_end = getParameter("endTime_end");
			HashMap<String, Object> paramHashMap = new HashMap<>();
			paramHashMap.put("id",id);
			paramHashMap.put("type","2");
			paramHashMap.put("startTime_begin",startTime_begin);
			paramHashMap.put("endTime_end",endTime_end);
			//PageBean pageBean = viewConsultancyStatisticsService.pageList(dc , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			//获取当前登录者
			String adminUserId = super.getLoginUser().getId();
			SysAdminUser user = super.getLoginUser();
			String ids = "";
			SysAdminUser sysAdminUser=this.sysAdminUserService.get(adminUserId);
			//获取当前登录者所拥有角色
			List<String> roleList = super.getLoginAdminRoles();

			if(roleList.contains(RoleConsts.TSS_COUNSELOR)||roleList.contains(RoleConsts.TSS_TEACHER)){
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + adminUserId + "') "));
				paramHashMap.put("adminUserId",adminUserId);
			} else{
				List<String> idsList = super.getUserIdByRoleAndSchololId(sysAdminUser.getSchoolId());
				ids = StringUtils.join(idsList, "','");
				dc.add(Restrictions.sqlRestriction(" adminUserId in ('" + ids + "') "));
				paramHashMap.put("adminUserId",ids);
			}

			PageBean pageBean = viewStaffStatisticssService.pageList(paramHashMap , paramPageBean.getPageNo() , paramPageBean.getPageSize());

			if(pageBean.getList()!=null){
				for (int i = 0; i < pageBean.getList().size(); i++) {
					ViewStaffStatistics StaffStatistics = (ViewStaffStatistics)pageBean.getList().get(i);
					Long sumAttendance = StaffStatistics.getSumAttendance();
					Long shouldAttend = StaffStatistics.getShouldAttend();

					BigDecimal bgSumAttendance = new BigDecimal(0);
					BigDecimal bgShouldAttend = new BigDecimal(0);
					if(sumAttendance!=null){
						bgSumAttendance = new BigDecimal(sumAttendance);
					}
					if(bgShouldAttend!=null){
						bgShouldAttend = new BigDecimal(shouldAttend);
					}
					BigDecimal hundred = new BigDecimal(100);
					Double attendanceRate = new Double(0);
					if(shouldAttend != 0){
						attendanceRate = bgSumAttendance.multiply(hundred).divide(bgShouldAttend, 2, BigDecimal.ROUND_HALF_UP).doubleValue();
						((ViewStaffStatistics) pageBean.getList().get(i)).setAttendanceRate(attendanceRate+"%");
					}else {
						((ViewStaffStatistics) pageBean.getList().get(i)).setAttendanceRate("0%");
					}


				}
			}

			mav.addObject(super.SEARCH_MAP , unLockMap);
			mav.addObject(super.PAGE_BEAN , pageBean);
			mav.addObject("searchFormId" , SEARCH_FORM);
			mav.addObject("actionUrl" , request.getRequestURI());
			mav.addObject("pagingBar" , pageBean.getPagingBar(SEARCH_FORM));
			mav.addObject("serializeNum" , SequenceUtil.getUpperCaseUUID());
			String requestURI = StringUtils.substringBeforeLast(request.getRequestURI() , "/");
			mav.addObject("editUrl" , requestURI + "/toEditView.do");
			mav.addObject("deleteUrl" , requestURI + "/delete.do");
			mav.addObject("batchDeleteUrl" , requestURI + "/batchDelete.do");
		} catch (Exception e) {
			try {
				throw e;
			} catch (IllegalAccessException e1) {
				e1.printStackTrace();
			} catch (InstantiationException e1) {
				e1.printStackTrace();
			}
		}

		return mav;
	}


}
